﻿using dapper.Repository;
using dapper.Repository.entity;
using dapper.Repository.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.BLL.DapperService
{
    /// <summary>
    /// dapper服务测试
    /// </summary>
    public  class UserService
    {

        /// <summary>
        /// 这是一个事务
        /// </summary>
        public void TestTrans()
        {
            UserRepository userRepository = new UserRepository();
            using (IDbConnection con = DataBaseConfig.GetSqlConnection())
            {
                var ss  =   userRepository.GetByPageIndex(2, 10, con);

                using (var ts = con.BeginTransaction())
                {
                    var entity = userRepository.GetById(3, con, ts, null);  // con.GetById<User>(3, null, ts);
                    entity.Name = "yuninyan";
                    userRepository.Update(entity, con, ts, null);
                    var deleEntity = userRepository.GetById(5, con, ts, null);  // con.GetById<User>(3, null, ts);
                    userRepository.Delete(deleEntity, con, ts);
                    ts.Commit();
                }
                  
            }
        }

    }
}
